<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.gouwudai.gobbs.file.*" %>
<%@ include file="../../common/common.jsp" %>
<%@ include file="../user_pass2.jsp" %>
<%
String errorMsg = "";
int remainSize = 0;
try
{
    int upfileSize = 0;
    try
	{
	    UploadFile uploadFile = new UploadFile();
		errorMsg = uploadFile.upload(request);
		
		upfileSize = Long.valueOf(uploadFile.getFileTotalSize()).intValue();
	}
	catch(Exception e)
	{
	    errorMsg = "上传文件失败！";
	}
	
	if(errorMsg.equals(""))
	{
		//更新用户信息
		try
		{
			IUserService userService = (IUserService)BeanManager.getBean("userService");
			remainSize  = userService.updateUpfileUsedSize(new Integer(upfileSize),userLogin.getUserId());
			userLogin.setUpfileUsedSize(userLogin.getUpfileUsedSize().intValue()+upfileSize);		
		}
		catch(Exception e)
		{
		    errorMsg = "更新用户信息失败！";
		}
	}
}
catch(Exception e)
{
    errorMsg = "上传文件失败！";
}

out.print("<script language='javascript'>");
if(errorMsg.equals(""))
{
    out.print("parent.document.getElementById('progressBarText').innerHTML = '上传成功！';");
}	
else 
{
    out.print("parent.alert(\"");
	out.print(errorMsg);
	out.print("\");");
}
out.print("parent.document.getElementById('resultMsg').innerHTML=\"");
out.print("(您的剩余上传空间约为：" + remainSize + "kb)\";");
out.print("</script>");
%>
